package thread;

import java.util.TreeMap;

public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println("hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t 线程结束");
        });
        t.start();

        t.join();  //在main线程,调用t.join效果,让main线程等待t先结束
        Thread.sleep(3000);
        System.out.println("main 线程结束");

    }
    public static void main1(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
        while(!Thread.currentThread().isInterrupted()){
            System.out.println("hello thread"+Thread.currentThread());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        });
        t.start();
        Thread.sleep(3000);
        t.interrupt();
        System.out.println("main  "+Thread.currentThread().getName());
    }
}
